﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>预约单管理</title>
    <#include "/common/link.ftl">
</head>
<body class="hold-transition skin-black sidebar-mini">
<div class="wrapper">
    <#include "/common/navbar.ftl">
    <!--菜单回显-->
    <#assign currentMenu="appointment"/>
    <#include "/common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>预约单管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <!--高级查询--->
                <div style="margin: 20px 0px 0px 10px">
                    <form class="form-inline" id="searchForm" action="/appointment/list" method="post">
                        <input type="hidden" name="currentPage" id="currentPage" value="1">
                        <div class="form-group">
                            <label>预约单流水号</label>
                            <input type="text" class="form-control"  placeholder="请输入预约单流水号">
                        </div>
                                <div class="form-group">
                                    <label>预约业务大类</label>
                                    <select class="form-control"  id="categoryId">
                                        <option value="">请选择业务大类</option>
                                        <option value="1">售卖</option>
                                        <option value="2">保养</option>
                                        <option value="3">修理</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>预约单状态</label>
                                    <select class="form-control" id="status">
                                        <option value="">全部</option>
                                        <#list statusEnums as s>
                                            <option value="${s.value}">${s.statusName}</option>
                                        </#list>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>门店查询</label>
                                    <select class="form-control"  id="businessId">
                                        <option value="">请选择门店</option>
                                        <option value="1">狼途汽车服务-深圳福田店</option>
                                        <option value="2">狼途汽车服务-广州黄埔店</option>
                                        <option value="3">狼途汽车服务-广州天河店</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>客户名称</label>
                                    <input type="text" class="form-control"  placeholder="请输入客户名称">
                                </div>

                                <div class="form-group">
                                    <label>客户手机号</label>
                                    <input type="text" class="form-control"  placeholder="请输入客户手机号">
                                </div>

                                <br/>
                                <br/>

                        <div class="form-group">
                            <label>预约时间查询：</label>
                            <input placeholder="请输入开始时间" type="text"  class="form-control  input-date-noss"   /> -
                            <input placeholder="请输入结束时间" type="text"  class="form-control input-date-noss"   />
                        </div>

                        <button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span> 查询</button>

                        <a href="#" class="btn btn-success btn-input">
                            <span class="glyphicon glyphicon-plus"></span> 添加
                        </a>
                    </form>

                </div>
                <div class="box-body table-responsive ">
                <table class="table table-hover table-bordered table-striped">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th>流水号</th>
                        <th>业务大类</th>
                        <th>预约说明</th>
                        <th>预约时间</th>
                        <th>客户名称</th>
                        <th>联系方式</th>
                        <th>预约门店</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <#list pageInfo.list as a>
                    <tr>
                        <td>${a_index+1}</td>
                        <td>${a.ano}</td>
                        <td>${a.systemDictionaryItem.title}</td>
                        <td>${a.info}</td>
                        <td>${a.appointmentTime?string("yyyy-MM-dd mm:ss")}</td>
                        <td>${a.contactName}</td>
                        <td>${a.contactTel}</td>
                        <td>${a.business.name}</td>
                        <td>${a.getStatusName()}</td>
                        <td>
                            <a href="#" class="btn btn-info btn-xs btn-input" data-json='${a.json}'>
                                <span class="glyphicon glyphicon-pencil"></span> 编辑
                            </a>
                            <a class="btn btn-xs btn-primary btn-status " data-id='${a.id}'  data-status='1' >
                                <span class="glyphicon glyphicon-phone-alt "></span> 确认预约</a>
                            <a class="btn btn-xs btn-danger btn-status" data-id='${a.id}' data-status='4' >
                                <span class="glyphicon glyphicon-remove"></span> 取消预约</a>
                            <a href="#" class="btn btn-success btn-xs btn-consume " data-id='${a.id}' data-status='2' data-ano="${a.ano}" >
                                <span class="glyphicon glyphicon-shopping-cart"></span> 确认到店
                            </a>
                        </td>
                    </tr>
                    </#list>
                    </tbody>
                </table>
                    <!--分页-->
                    <#include "/common/page.ftl">
                </div>

            </div>
        </section>
    </div>
    <#include "/common/footer.ftl">
</div>


<#-- 文件上传模态框 -->
<!--模态框-->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="myModalLabel">新增/编辑</h4>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
            </div>

            <form id="editForm" action="/appointment/saveOrUpdate" method="post" >
                <div class="modal-body">
                    <input type="hidden" name="id">
                    <input type="hidden" name="status">
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">预约门店：</label>
                        <div class="col-sm-7">
                            <select class="form-control" id="businessSelect" name="business.id" >
                                <option value="">请选择预约门店</option>
                                <option value="1">狼途汽车服务-深圳福田店</option>
                                <option value="2">狼途汽车服务-广州黄埔店</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label ">预约时间：</label>
                        <div class="col-sm-7">
                            <input type="text"  class="form-control input-date-noss " placeholder="请输入预约时间" name="appointmentTime"/>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">业务大类：</label>
                        <div class="col-sm-7">
                            <select class="form-control" id="categorySelect" name="systemDictionaryItem.id" >
                                <option value="">请选择业务大类</option>
                                <option value="1">售卖</option>
                                <option value="2">保养</option>
                            </select>
                        </div>
                    </div>

                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">联系人：</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control" name="contactName"
                                   placeholder="请输入联系人">
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">联系电话：</label>
                        <div class="col-sm-7">
                            <input type="text" class="form-control" name="contactTel"
                                   placeholder="请输入联系电话">
                        </div>
                    </div>
                    <div class="form-group row">
                        <label class="col-sm-3 col-form-label">预约说明：</label>
                        <div class="col-sm-7">
                            <textarea type="text" class="form-control" name="info"
                                      placeholder="请输入预约说明"></textarea>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="submit" class="btn btn-primary btn-submit">保存</button>
                </div>
            </form>
        </div>
    </div>
</div>
<script>
    //关于下拉框的数据回显
    // 获取业务大类，我们可以通过type_id = 1 来获取，使用ajax提交更好（页面加载完之前局部提交更好）
    //写在后端的话，代码耦合性低，一改的话全部都要改

    // 而我们参数{id：1}这样不见名知意，或者当需要更换业务时，如果要更改其他的业务我们更改麻烦
    // 我们使用多表查询的话，参数sn：bussuiness_id,这样见名知意，方便项目的迭代，和更新方便

    $.get("/appointment/selectBySn",{sn:'business'},function (date) {
        var  str= '<option value="">请选择业务大类</option>';
        $.each(date,function (index,element) {
            str += '<option value="'+element.id+'">'+element.title+'</option>';
        })
        $('#categoryId').html(str);
        $('#categorySelect').html(str);
    })

    $.get("/appointment/selectByBussiness",function (date) {
        var  str= '<option value="">请选择业务门店</option>';
        $.each(date,function (index,element) {
            str += '<option value="'+element.id+'">'+element.name+'</option>';
        })
        $('#businessId').html(str);
        $('#businessSelect').html(str);
    })

    $('.btn-input').click(function () {
        let json = $(this).data('json');
        $('input').val('');
        $('textarea').val('');
        $('#businessSelect').val('');
        $('#categorySelect').val('');
        if (json){
            $('#businessSelect').val(json.businessId);
            $('#categorySelect').val(json.sdi_id);
            $('input[name=id]').val(json.id);
            $('input[name=appointmentTime]').val(json.appointmentTime);
            $('input[name=contactName]').val(json.contactName);
            $('input[name=contactTel]').val(json.contactTel);
            $('textarea[name=info]').val(json.info);
            // $('textarea').html(json.info);
        }

         $('#editModal').modal('show');
    })


    function updateStatus(id,status){
        $.get("/appointment/updateStatus",{id:id,status:status},function (data) {
            if (data.success){
                Swal.fire({
                    title: data.msg,
                    icon: 'success',
                    confirmButtonColor: '#3085d6',
                    confirmButtonText: 'OK',
                }).then((result) => {
                    if (result.value) {
                        window.location.reload();
                    }
                })
            }else {
                Swal.fire({
                    title: data.msg,
                    icon: 'error',
                    confirmButtonColor: '#3085d6',
                    confirmButtonText: 'OK',

                })

            }
        })
    }



     $('.btn-status').click(function () {
         let id = $(this).data('id');
         let status = $(this).data('status');
         $.get("/appointment/updateStatus",{id:id,status:status},function (data) {
             if (data.success){
                 Swal.fire({
                     title: data.msg,
                     icon: 'success',
                     confirmButtonColor: '#3085d6',
                     confirmButtonText: 'OK',
                 }).then((result) => {
                     if (result.value) {
                         window.location.reload();
                     }
                 })
             }else {
                 Swal.fire({
                     title: data.msg,
                     icon: 'error',
                     confirmButtonColor: '#3085d6',
                     confirmButtonText: 'OK',

                 })

             }
         })
      })



    $('.btn-consume').click(function () {
        let id = $(this).data('id');
        Swal.fire({
            title: '温馨提示?',
            text: "用户是否到店?",
            icon: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: '是',
            cancelButtonText: '否'
        }).then((result) => {
            if (result.value) {
                Swal.fire({
                    title: '温馨提示',
                    text: '用户是否进行消费?',
                    icon: 'warning',
                    showCancelButton: true,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: '是',
                    cancelButtonText: '否'
                }).then((result) => {
                    if (result.value) {  //用户到店，进行消费，状态改为消费中，跳转到结算明细页面
                        let ano = $(this).data('ano');
                        let id = $(this).data('id');
                        console.log(ano)
                        $.get("/consumption/save",{appointmentAno:ano},function (data) {
                            console.log(data.data)
                        Swal.fire(
                            '操作成功!',
                            'Your file has been deleted.',
                            'success')
                            window.location.href = "/consumption/input?id="+data.data.id;
                       })
                    }else {   //用户到店没有进行消费，状态改为归档
                       updateStatus(id,3);
                    }
                })

            }else {  //用户没有到店，状态改为废弃
                updateStatus(id,4)
            }
        })

    })

</script>

</body>
</html>
